package app.service.sys;

import org.springframework.stereotype.Repository;
import org.springframework.util.StringUtils;

import app.model.sys.SysRole;
import base.PageInfo;
import base.category.sys.YesOrNo;
import base.service.BaseService;

@Repository
public class SysRoleService extends BaseService<SysRole> {

	public PageInfo queryPageList(PageInfo pageInfo) {
		String sql = "select * from sys_role a where a.is_use = " + YesOrNo.YES + " order by a.create_time";
		PageInfo page = getDao().queryPageListBySql(pageInfo, sql);
		return page;
	}

	public SysRole queryEntityById(String id) {
		String sql = "select * from sys_role a where a.id = '"+id+"'";
		SysRole entity = getDao().queryEntityBySql(sql , SysRole.class);
		return entity;
	}

	public void delEntity(String ids) {
		if(!StringUtils.isEmpty(ids)){
			String[] idsArray = ids.split(",");
			for (int i = 0; i < idsArray.length; i++) {
				SysRole load = getDao().queryEntityById(idsArray[i], SysRole.class);
				getDao().del(load);
			}
		}
	}

	public void saveEntity(SysRole sysRole) {
		getDao().save(sysRole);
	}

	public void updateEntity(SysRole sysRole) {
		getDao().mergeAndUpdate(sysRole);
	}
}
